package com.tianhai.db.index;

import java.io.File;

import com.tianhai.db.DiskManager;

/**
 * 调试搜索问题
 */
public class DebugSearchTest {
    public static void main(String[] args) {
        try {
            String dbFilePath = "debug_test.db";
            new File(dbFilePath).delete();
            
            DiskManager diskManager = new DiskManager(dbFilePath);
            BPlusTree bTree = new BPlusTree(diskManager, 4); // 使用小的阶数便于调试
            
            // 插入少量数据
            System.out.println("插入数据...");
            for (int i = 1; i <= 20; i++) {
                bTree.insert(i, i * 10);
                System.out.println("  插入: key=" + i + ", value=" + (i * 10));
            }
            
            System.out.println("\n搜索测试:");
            // 测试搜索
            for (int i = 1; i <= 20; i++) {
                Integer result = bTree.search(i);
                if (result == null || result != i * 10) {
                    System.out.println("✗ key=" + i + " 搜索失败: expected=" + (i * 10) + ", actual=" + result);
                } else {
                    System.out.println("✓ key=" + i + " 搜索成功: " + result);
                }
            }
            
            diskManager.close();
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
